'use strict';
require('./index.css')
require('page/common/nav/index.js')
require('page/common/header/index.js')
var _mm = require('util/mm.js')
var _payment = require('service/payment-service.js')
var template = require('./index.string')

var page = {
    data: {
        orderNumber : _mm.getUrlParam('orderNumber')
    },
    init: function () {
        this.onLoad();
    },
    onLoad: function () {
        this.loadPaymentInfo()
    },
    loadPaymentInfo : function(){
        var _this       = this , 
            $pageWrap    = $('.page-wrap'),
            paymentHtml = '';
            $pageWrap.html('<div class="loading"></div>')
        _payment.getPaymentInfo(_this.data.orderNumber,function(res){
            console.log(res)
            paymentHtml = _mm.renderHtml(template, res);
            $pageWrap.html(paymentHtml);
            _this.listenOrderStatus()
        },function(errMsg){
            console.log(errMsg)
            $pageWrap.html('<div class="err-tip">'+ errMsg +'</div>')
        })
    },
    // 监听订单状态
    listenOrderStatus : function(){
        var _this = this;
        this.paymentTimer = window.setInterval(function(){
            _payment.getPaymentStatus(_this.data.orderNumber,function(res){
                if(res == true){
                    window.location.href = './result.html?type=payment&orderNumber='+_this.data.orderNumber
                }
            },function(){

            })
        },5000)
    }


}

$(function () {
    page.init()
})